<?php
function plugin_render() {
    $url = '';
    $favicon = '';
    $error = '';
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $url = trim($_POST['url'] ?? '');
        if (filter_var($url, FILTER_VALIDATE_URL)) {
            $favicon = 'https://favicon.cccyun.cc/' . $url;
        } else {
            $error = '请输入正确的网址（如 https://www.example.com）';
        }
    }
    ?>
    <form method="post" class="space-y-4">
      <div class="flex gap-2">
        <input type="text" name="url" value="<?=htmlspecialchars($url)?>" class="flex-1 border rounded px-3 py-2" placeholder="请输入网址" required>
        <button type="submit" class="bg-blue-500 text-white px-6 py-2 rounded">获取</button>
      </div>
      <?php if ($error): ?>
        <div class="text-red-500"><?=htmlspecialchars($error)?></div>
      <?php endif; ?>
    </form>
    <?php if ($favicon): ?>
      <div class="mt-4 flex items-center gap-4">
        <img src="<?=htmlspecialchars($favicon)?>" alt="favicon" class="w-12 h-12 border rounded shadow">
        <a href="<?=htmlspecialchars($favicon)?>" target="_blank" class="text-blue-600 underline">新窗口打开</a>
      </div>
    <?php endif;
} 